import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP

from lib.webui_permission import  *

class c73308:
    name = '验证修改密码时的有效长度验证功能-73308' # 测试用例名字

# 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        wd = open_browser()
        user_login(wd)

    #清除方法
    def teardown(self):
        wd = get_global_webdriver()
        wd.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()

        time.sleep(2)
        STEP(2, "修改密码长度为6")
        change_pwd_btn = driver.find_element(By.CLASS_NAME,
                                             "avatar-wrapper"
                                             )
        change_pwd_btn.click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        expect_success = "修改密码成功"
        time.sleep(3)
        success_msg = message_check(driver,
                                    "body > div.el-notification.right > div > div.el-notification__content > p"
                                    )
        CHECK_POINT("提示信息是否一致", success_msg == expect_success)
        time.sleep(5)


        time.sleep(2)
        STEP(3, "修改密码长度为7")
        change_pwd_btn.click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("a1.a1.a")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("a1.a1.a")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        expect_success1 = "修改密码成功"
        time.sleep(3)
        success_msg1 = message_check(driver,
                                    "body > div.el-notification.right > div > div.el-notification__content > p"
                                    )
        CHECK_POINT("提示信息是否一致", success_msg1 == expect_success1)
        time.sleep(5)

        time.sleep(2)
        STEP(3, "修改密码长度为12")
        change_pwd_btn.click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("a1.a1.a")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("a1.a1.a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("a1.a1.a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        expect_success2 = "修改密码成功"
        time.sleep(3)
        success_msg2 = message_check(driver,
                                     "body > div.el-notification.right > div > div.el-notification__content > p"
                                     )
        CHECK_POINT("提示信息是否一致", success_msg2 == expect_success2)
        time.sleep(3)

        time.sleep(2)
        STEP(5, "还原密码")
        change_pwd_btn.click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                                "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                                ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("a1.a1.a1.a1.")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()


